package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysStockDetailsMapper;
import com.ruoyi.system.domain.SysStockDetails;
import com.ruoyi.system.service.ISysStockDetailsService;

/**
 * 库存明细Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-04-25
 */
@Service
public class SysStockDetailsServiceImpl implements ISysStockDetailsService 
{
    @Autowired
    private SysStockDetailsMapper sysStockDetailsMapper;
    @Autowired
    private SysUserMapper sysUserMapper;

    /**
     * 查询库存明细
     * 
     * @param id 库存明细主键
     * @return 库存明细
     */
    @Override
    public SysStockDetails selectSysStockDetailsById(String id)
    {
        return sysStockDetailsMapper.selectSysStockDetailsById(id);
    }

    /**
     * 查询库存明细列表
     * 
     * @param sysStockDetails 库存明细
     * @return 库存明细
     */
    @Override
    public List<SysStockDetails> selectSysStockDetailsList(SysStockDetails sysStockDetails)
    {
        List<SysStockDetails> resList = sysStockDetailsMapper.selectSysStockDetailsList(sysStockDetails);
        for (SysStockDetails item : resList) {
            SysUser sysUser = sysUserMapper.selectUserById(Long.parseLong(item.getCreateBy()));
            item.setCreateByName(sysUser.getUserName());
        }
        return resList;
    }

    /**
     * 新增库存明细
     * 
     * @param sysStockDetails 库存明细
     * @return 结果
     */
    @Override
    public int insertSysStockDetails(SysStockDetails sysStockDetails)
    {
        sysStockDetails.setCreateTime(DateUtils.getNowDate());
        return sysStockDetailsMapper.insertSysStockDetails(sysStockDetails);
    }

    /**
     * 修改库存明细
     * 
     * @param sysStockDetails 库存明细
     * @return 结果
     */
    @Override
    public int updateSysStockDetails(SysStockDetails sysStockDetails)
    {
        sysStockDetails.setUpdateTime(DateUtils.getNowDate());
        return sysStockDetailsMapper.updateSysStockDetails(sysStockDetails);
    }

    /**
     * 批量删除库存明细
     * 
     * @param ids 需要删除的库存明细主键
     * @return 结果
     */
    @Override
    public int deleteSysStockDetailsByIds(String[] ids)
    {
        return sysStockDetailsMapper.deleteSysStockDetailsByIds(ids);
    }

    /**
     * 删除库存明细信息
     * 
     * @param id 库存明细主键
     * @return 结果
     */
    @Override
    public int deleteSysStockDetailsById(String id)
    {
        return sysStockDetailsMapper.deleteSysStockDetailsById(id);
    }
}
